package com.ruoyi.web.controller.website;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.website.domain.WebSort;
import com.ruoyi.website.service.IWebSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 网页分类Controller
 * 
 * @author lzb
 * @date 2023-08-08
 */
@RestController
@RequestMapping("/website/web")
public class WebSortController extends BaseController
{
    @Autowired
    private IWebSortService webSortService;

    /**
     * 查询网页分类列表
     */
    @PreAuthorize("@ss.hasPermi('website:web:list')")
    @GetMapping("/list")
    public AjaxResult list(WebSort webSort)
    {
        List<WebSort> list = webSortService.selectWebSortList(webSort);
        return success(list);
    }

    /**
     * 导出网页分类列表
     */
    @PreAuthorize("@ss.hasPermi('website:web:export')")
    @Log(title = "网页分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WebSort webSort)
    {
        List<WebSort> list = webSortService.selectWebSortList(webSort);
        ExcelUtil<WebSort> util = new ExcelUtil<WebSort>(WebSort.class);
        util.exportExcel(response, list, "网页分类数据");
    }

    /**
     * 获取网页分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('website:web:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") String categoryId)
    {
        return success(webSortService.selectWebSortByCategoryId(categoryId));
    }

    /**
     * 新增网页分类
     */
    @PreAuthorize("@ss.hasPermi('website:web:add')")
    @Log(title = "网页分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebSort webSort)
    {
        return toAjax(webSortService.insertWebSort(webSort));
    }

    /**
     * 修改网页分类
     */
    @PreAuthorize("@ss.hasPermi('website:web:edit')")
    @Log(title = "网页分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebSort webSort)
    {
        return toAjax(webSortService.updateWebSort(webSort));
    }

    /**
     * 删除网页分类
     */
    @PreAuthorize("@ss.hasPermi('website:web:remove')")
    @Log(title = "网页分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable String[] categoryIds)
    {
        return toAjax(webSortService.deleteWebSortByCategoryIds(categoryIds));
    }
}
